package com.ruitu.health_1.util;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ruitu.health_1.R;

public class CustomDialogUtil extends Dialog implements CustomInterface {
    private Context mContext;
    private int layoutId;
    private OnBtnClickListener onBtnClickListener;
    private String title, leftBtn="确定", rightBtn="取消";

    protected CustomDialogUtil(@NonNull Context context) {
        super(context);
    }

    public CustomDialogUtil(@NonNull Context context, int themeResId) {
        super(context, themeResId);

    }

    protected CustomDialogUtil(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public CustomDialogUtil(Context context, String title, OnBtnClickListener onBtnClickListener) {
        super(context,R.style.CustomDialogStyle);
        this.mContext = context;
        this.title = title;
        this.onBtnClickListener = onBtnClickListener;
        initView();
    }

    public CustomDialogUtil(Context context, String title, String leftBtn, String rightBtn, OnBtnClickListener onBtnClickListener) {
        super(context,R.style.CustomDialogStyle);
        this.mContext = context;
        this.title = title;
        this.leftBtn = leftBtn;
        this.rightBtn = rightBtn;
        this.onBtnClickListener = onBtnClickListener;
        initView();
    }

    public CustomDialogUtil(Context context,View view,int style){
        super(context,style);
        setContentView(view);

    }

    private void initView() {
        View view = View.inflate(mContext, R.layout.dialog_about_order, null);
        setContentView(view);
        TextView tv_Left_btn = view.findViewById(R.id.tv_all_shipped);
        TextView tv_right_btn = view.findViewById(R.id.tv_radio_shipped);
        TextView tv_title = view.findViewById(R.id.tv_title);
        tv_title.setText(title);
        tv_Left_btn.setText(leftBtn);
        tv_right_btn.setText(rightBtn);
        tv_Left_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnClickListener.onLeftClick();
            }
        });
        tv_right_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBtnClickListener.onRightClick();
            }
        });
    }

    public void setOnBtnClickListener(OnBtnClickListener onBtnClickListener) {
        this.onBtnClickListener = onBtnClickListener;
    }
}
